package com.school.util;

import java.io.Serializable;

import com.alibaba.fastjson.JSONObject;

/** 
 * 实现对象和json字符串之间的转换
 */  
public class JsonUtil{
		private static final long serialVersionUID = 1L;
		/**
		 * 返回码值,默认值Const.FAI
		 */
		private int res=Const.FAIL;
		/**
		 * 返回码值解析
		 */
		private String resMsg;
		/**
		 * 返回对象
		 */
		private Object obj;
		
		public int getRes() {
			return res;
		}
		public void setRes(int res) {
			this.res = res;
		}
		public String getResMsg() {
			return resMsg;
		}
		public void setResMsg(String resMsg) {
			this.resMsg = resMsg;
		}
		public Object getObj() {
			return obj;
		}
		public void setObj(Object obj) {
			this.obj = obj;
		}
		
		/**
		 * 设置成功值
		 * @param obj  设置对象  
		 * @param resMsg  设置码值解析
		 */
		public void setSucceed(Object obj,String resMsg){
			this.setResMsg(resMsg);
			this.setSucceed(obj);
			this.setRes(Const.SUCCEED);
		}
		/**
		 * 设置成功值
		 * @param obj 设置对象    
		 */
		public void setSucceed(Object obj){
			this.obj = obj;
			this.setRes(Const.SUCCEED);
		}
		/**
		 * 设置成功值
		 * @param resMsg 返回码值解析
		 */
		public void setSucceedMsg(String resMsg){
			this.setRes(Const.SUCCEED);
			this.setResMsg(resMsg);
		}
		/**
		 * 设置失败值
		 * @param resMsg 返回码值解析
		 */
		public void setFailMsg(String resMsg){
			this.obj = null;
			this.setRes(Const.FAIL);
			this.setResMsg(resMsg);
		}
		
		
		
		/**
		 * 设置失败值
		 * @param resMsg 返回码值解析
		 */
		public void setServerException(String resMsg){
			this.obj = null;
			this.setRes(Const.serverException);
			this.setResMsg(resMsg);
		}
		
		
		
		/**
		 * 设置失败值
		 * @param resMsg 返回码值解析
		 */
		public void setnotClassId(String resMsg){
			this.obj = null;
			this.setRes(Const.notClassId);
			this.setResMsg(resMsg);
		}
		
		/**
		 * 设置失败值
		 * @param resMsg 返回码值解析
		 */
		public void setnotMac(String resMsg){
			this.obj = null;
			this.setRes(Const.notMac);
			this.setResMsg(resMsg);
		}
		
		
		/**
		 * 设置失败值
		 * @param resMsg 返回码值解析
		 */
		public void setSchool(String resMsg){
			this.obj = null;
			this.setRes(Const.notSchool);
			this.setResMsg(resMsg);
		}
		
		
		/**
		 * 重复打卡
		 * @param resMsg 返回码值解析
		 */
		public void setRepeatCard(String resMsg){
			this.obj = null;
			this.setRes(Const.repeatCard);
			this.setResMsg(resMsg);
		}
		
		
		
		/**
		 * 设置二级成功值
		 * @param resMsg 返回码值解析
		 */
		public String setSucceedMsg(String msg  , Object o){
			JSONObject j = new JSONObject();
			j.put("registerInformation", o);
			j.put("register", Const.SUCCEED);
			j.put("registerMsg", msg);
			return j.toJSONString();
		}
		
		
		
		
		public JSONObject toJSONString(){
			JSONObject ret=new JSONObject();
			ret.put("errCode", res);
			ret.put("errMsg", resMsg);
			ret.put("data", obj);
			return ret;
		}
	
		@Override
		public String toString() {
			return "AjaxRes [res=" + res + ", resMsg=" + resMsg + ", obj=" + obj + "]";
		}	

}
